<?php


namespace App\Http\Controllers\applets\model;


use Illuminate\Support\Facades\DB;

class AppLogModel
{
    public static function queryFirst($where,$field){
        return DB::table('t_app_log')->where($where)->first($field);
    }

    public static function queryLikeParent($where,$param){
        return DB::table('t_app_log as a')
            ->leftJoin('t_parent_app as p','a.parent_app_id','=','p.id')
            ->where('a.create_time','>=',$param['create_time'])
            ->where('a.update_time','<=',$param['end_time'])
            ->where($where)
            ->get(['a.id','p.app_name','p.app_img','a.create_time','a.remarks','a.minute','a.update_time']);
    }

    public static function queryLikeTeacher($where,$param){
        return DB::table('t_app_log as a')
            ->leftJoin('t_teacher_app as t','a.teacher_app_id','=','t.id')
            ->where('a.create_time','>=',$param['create_time'])
            ->where('a.update_time','<=',$param['end_time'])
            ->where($where)
            ->get(['a.id','t.app_name','t.app_img','a.create_time','a.remarks','a.minute','a.update_time']);
    }

    public static function queryAddLikeParent($where,$param){
        $leftJoin = " right join t_parent_app as p on a.parent_app_id=p.id";
        $str = " where a.sn_value='$where[snValue]' and a.create_time>='$param[create_time]' and a.update_time<='$param[end_time]'";
        $group = " group by a.sn_value,a.parent_app_id";
        return DB::select("select sum(a.minute) as minute,a.parent_app_id from t_app_log as a ".$leftJoin.$str.$group);
    }

    public static function queryAddLikeTeacher($where,$param){
        $leftJoin = " right join t_teacher_app as p on a.parent_app_id=p.id";
        $str = " where a.sn_value='$where[snValue]' and a.create_time>='$param[create_time]' and a.update_time<='$param[end_time]'";
        $group = " group by a.sn_value,a.teacher_app_id";
        return DB::select("select sum(a.minute) as minute,a.teacher_app_id from t_app_log as a ".$leftJoin.$str.$group);
    }

}